package com.pe.regope.integracion.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.pe.regope.integracion.dao.IpnpDAO;
import com.pe.regope.negocio.dto.ConclusionDTO;
import com.pe.regope.negocio.dto.IpnpDTO;
import com.pe.regope.negocio.dto.TipoIpnpDTO;

@Repository
public class IpnpDAOImpl extends SqlMapClientDaoSupport implements IpnpDAO{

	@Autowired
	public IpnpDAOImpl(SqlMapClient sqlMapClient){
		super.setSqlMapClient(sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<IpnpDTO> obtenerListaIPNPdeBD() throws DataAccessException{
		// TODO Auto-generated method stub
		return (List<IpnpDTO>)getSqlMapClientTemplate().queryForList("Ipnp.obtenerListaIPNP");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<IpnpDTO> obtenerListaIPNPporNumero(Integer numero) throws DataAccessException{
		// TODO Auto-generated method stub
		return (List<IpnpDTO>)getSqlMapClientTemplate().queryForList("Ipnp.obtenerListaIPNPporNumero",numero);
	}
	
	@Override
	public boolean verificarSiExisteIpnp(String nroIpnp){
		return (Boolean) getSqlMapClientTemplate().queryForObject("Ipnp.existeIPNP");
	}
	
	@Override
	public void ingresarIPNP(String nroIpnp,Date fechaIpnp,String numAclara,Date fechaAclara,TipoIpnpDTO tipopnp,ConclusionDTO conclusion){
		IpnpDTO registra = new IpnpDTO();
		registra.setNumeroIPNP(Integer.parseInt(nroIpnp));
		registra.setFechaIPNP(fechaIpnp);
		if(numAclara!=null && !numAclara.equalsIgnoreCase("")){
			registra.setNumAclara(Integer.parseInt(numAclara));
		} else {
			registra.setNumAclara(0);
		}
		if(fechaAclara!=null){
			registra.setFechaAclara(fechaAclara);
		} else {
			registra.setFechaAclara(new Date());
		}
		registra.setIdTipoIPNP(tipopnp.getIdTipoIpnp());
		registra.setIdConclusion(conclusion.getIdConclusion());
		getSqlMapClientTemplate().insert("", registra);
	}
}
